<?php

interface Subject
{
    public function registerObj(Observer $observer);
    public function sendNotify();
}

interface Observer
{
    public function notify($arg);
}

class MainSubject implements Subject
{
    static $instance = null;
    private $objs = [];

    public function registerObj(Observer $observer)
    {
        $this->objs[] = $observer;
    }

    public function sendNotify()
    {
        foreach ($this->objs as $index=>$obj) {
            $obj->notify($index);
        }
    }

    public static function getInstance()
    {
        if (!self::$instance)
            self::$instance = new MainSubject();
        return self::$instance;
    }
}

class obj1 implements Observer
{
    public function __construct()
    {
        MainSubject::getInstance()->registerObj($this);
    }

    public function notify($arg)
    {
        print "$arg <br>";
        print "this is obj1<br>";
    }
}

class obj2 implements Observer
{

    public function __construct()
    {
        MainSubject::getInstance()->registerObj($this);
    }

    public function notify($arg)
    {
        print "$arg <br>";
        print "this is obj2<br>";
    }
}

$obj1 = new obj1();
$obj2 = new obj2();

MainSubject::getInstance()->sendNotify();

